const path = require('path');
// https://github.com/arackaf/customize-cra/blob/master/api.md#usebabelrc
// https://zhuanlan.zhihu.com/p/52775065
// https://github.com/ant-design/babel-plugin-import
// https://github.com/timarney/react-app-rewired/blob/HEAD/README_zh.md
const {
    override,
    addDecoratorsLegacy,
    disableEsLint,
    addBundleVisualizer,
    addWebpackAlias,
    useBabelRc,
    adjustStyleLoaders,
} = require("customize-cra");

module.exports = override(
    useBabelRc(),
    // enable legacy decorators babel plugin
    addDecoratorsLegacy(),

    // disable eslint in webpack
    disableEsLint(),

    // add webpack bundle visualizer if BUNDLE_VISUALIZE flag is enabled
    process.env.BUNDLE_VISUALIZE === 1 && addBundleVisualizer(),

    // add an alias for "ag-grid-react" imports
    addWebpackAlias({
        ["@"]: path.resolve(__dirname, "src/")
    }),

    // config global scss variables
    adjustStyleLoaders(rule => {
        if (rule.test.toString().includes("scss")) {
            rule.use.push({
                loader: require.resolve("sass-resources-loader"),
                options: {
                    resources: "./src/styles/index.scss" //这里是你自己放公共scss变量的路径
                }
            });
        }
    }),
);
